from django.db import models


class Workflow(models.Model):
    name = models.CharField(max_length=20)
    description = models.CharField(max_length=150, blank=True, null=True)
    effective_time = models.IntegerField(blank=True, null=True)
    end = models.IntegerField(blank=True, null=True)
    start = models.IntegerField(blank=True, null=True)
    flowchart = models.TextField(blank=True, null=True)
    founder = models.CharField(max_length=30, blank=True, null=True)
    rectime = models.DateTimeField(blank=True, null=True)
    update_time = models.DateTimeField(blank=True, null=True)
    workflow_type = models.CharField(max_length=50)

    class Meta:

        db_table = 'tb_workflow'


class Workflowrecord(models.Model):
    pdf = models.CharField(max_length=200)
    #pdf3 = models.CharField(max_length=200)
    pdf55 = models.CharField(max_length=200)  # Field name made lowercase.
    no = models.CharField(db_column='NO', max_length=50, blank=True, null=True)  # Field name made lowercase.
    desc = models.CharField(max_length=200, blank=True, null=True)
    # applicant = models.CharField(max_length=45, blank=True, null=True)
    status = models.CharField(max_length=45, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    workflow = models.ForeignKey(Workflow)
    end_time = models.CharField(max_length=45, blank=True, null=True)
    org_id = models.IntegerField()

    class Meta:
        db_table = 'tb_workflowrecord'

class WorkflowApprovalRecord(models.Model):
    workflow_record = models.ForeignKey(Workflowrecord)
    status = models.CharField(max_length=20, blank=True, null=True)
    approver = models.CharField(max_length=20, blank=True, null=True)
    next = models.CharField(max_length=20, blank=True, null=True)
    start_time = models.DateTimeField(blank=True, null=True)
    end_time = models.DateTimeField(blank=True, null=True)
    order_number = models.IntegerField(blank=True, null=True)
    action = models.CharField(max_length=20, blank=True, null=True)
    next_approver = models.CharField(max_length=100)
    username = models.CharField(max_length=45, blank=True, null=True)
    #this = models.CharField(max_length=20, blank=True, null=True)
    class Meta:
        db_table = 'tb_workflow_approval_record'

class TbApplyform(models.Model):
    name = models.CharField(max_length=50)
    card_id = models.CharField(max_length=30, blank=True, null=True)
    form = models.ForeignKey('TbForms', blank=True, null=True)
    form_content = models.TextField(blank=True, null=True)
    apply_type = models.CharField(max_length=50, blank=True, null=True)
    applicant = models.CharField(max_length=50, blank=True, null=True)
    apply_dept = models.CharField(max_length=50, blank=True, null=True)
    apply_time = models.DateTimeField(blank=True, null=True)
    apply_endtime = models.DateTimeField(blank=True, null=True)
    form_footer = models.CharField(max_length=255, blank=True, null=True)
    sign_status = models.IntegerField(blank=True, null=True)
    wrecord = models.ForeignKey(Workflowrecord)
    desc = models.CharField(max_length=255, blank=True, null=True)
    file1 = models.CharField(max_length=255, blank=True, null=True)
    file2 = models.CharField(max_length=255, blank=True, null=True)
    file3 = models.CharField(max_length=255, blank=True, null=True)
    file4 = models.CharField(max_length=255, blank=True, null=True)
    file5 = models.CharField(max_length=255, blank=True, null=True)
    file6 = models.CharField(max_length=255, blank=True, null=True)
    degree = models.CharField(max_length=20, blank=True, null=True)
    sign_image = models.CharField(max_length=20, blank=True, null=True)
    layout = models.CharField(max_length=25, blank=True, null=True)
    pdf = models.CharField(max_length=25, blank=True, null=True)
    is_form = models.IntegerField(blank=True, null=True)

    class Meta:
        db_table = 'tb_applyform'



class TbColor(models.Model):
    color = models.CharField(max_length=50)
    desc = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        db_table = 'tb_color'


class TbFormheader(models.Model):
    header_img = models.CharField(max_length=50, blank=True, null=True)
    header_url = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        db_table = 'tb_formheader'


class TbForms(models.Model):
    table_name = models.CharField(max_length=100)
    table_content = models.TextField(blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    table_type = models.ForeignKey('TbFormtype', blank=True, null=True)
    creater = models.CharField(max_length=15, blank=True, null=True)
    version = models.CharField(max_length=10, blank=True, null=True)
    status = models.IntegerField(blank=True, null=True)
    desc = models.CharField(max_length=255, blank=True, null=True)
    workflow = models.ForeignKey('Workflow', blank=True, null=True)
    modify_time = models.CharField(max_length=15, blank=True, null=True)
    sign_type = models.CharField(max_length=20, blank=True, null=True)
    layout = models.CharField(max_length=20, blank=True, null=True)

    class Meta:
        db_table = 'tb_forms'


class TbFormtype(models.Model):
    forms_type = models.CharField(max_length=50, blank=True, null=True)
    statue = models.IntegerField(blank=True, null=True)
    type_english = models.CharField(max_length=100,blank=True,null=True)
    type_code = models.CharField(max_length=15,blank=True,null=True)
    type_id = models.IntegerField(blank=True, null=True)

    class Meta:
        db_table = 'tb_formtype'

class TbFormfile(models.Model):
     name = models.CharField(max_length=50)
     url = models.CharField(max_length=255)
     status = models.IntegerField(blank=True,null=True)
     forms_id = models.ForeignKey('TbApplyform',blank=True,null=True)


class Meta:
    db_table = 'tb_formfile'

class TbDatasource(models.Model):
    api = models.CharField(max_length=100, blank=True, null=True)
    apiname = models.CharField(db_column='apiName', max_length=100, blank=True, null=True)  # Field name made lowercase.
    apidescription = models.CharField(db_column='apiDescription', max_length=255, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        # managed = False
        db_table = 'tb_datasource'


class TbSourcelist(models.Model):
    id = models.IntegerField(primary_key=True)
    source = models.ForeignKey(TbDatasource)
    apiparamname = models.CharField(db_column='apiParamName', max_length=255, blank=True, null=True)  # Field name made lowercase.
    apiparamdescription = models.CharField(db_column='apiParamDescription', max_length=255, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        # managed = False
        db_table = 'tb_sourcelist'

class TbUser(models.Model):
    password = models.CharField(max_length=128)
    last_login = models.DateTimeField(blank=True, null=True)
    is_superuser = models.IntegerField()
    username = models.CharField(unique=True, max_length=30)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.CharField(max_length=254)
    is_staff = models.IntegerField()
    is_active = models.IntegerField()
    date_joined = models.DateTimeField()
    nfc_id = models.CharField(db_column='NFC_id', max_length=100, blank=True, null=True)  # Field name made lowercase.
    ext = models.CharField(max_length=50, blank=True, null=True)
    short_number = models.CharField(max_length=50, blank=True, null=True)
    mobile_phone = models.CharField(max_length=50, blank=True, null=True)
    head = models.CharField(max_length=100, blank=True, null=True)
    sign = models.CharField(max_length=100, blank=True, null=True)
    # site = models.ForeignKey(TbSite)
    # status = models.ForeignKey(TbStatus)
    # org_id = models.IntegerField()
    # duty = models.ForeignKey(TbDuty, blank=True, null=True)
    entry_date = models.DateField()
    sex = models.CharField(max_length=10)
    status_id = models.IntegerField()
    class Meta:
        db_table = 'tb_user'

class TbOrg(models.Model):
    org_name = models.CharField(max_length=100)
    parent_id = models.IntegerField(blank=True, null=True)
    create_date = models.DateTimeField()
    org_code = models.CharField(max_length=50, blank=True, null=True)
    cost_code = models.CharField(max_length=50, blank=True, null=True)
    org_desc = models.CharField(max_length=500, blank=True, null=True)
    org_desc2 = models.CharField(max_length=500, blank=True, null=True)
    # org_level = models.ForeignKey('TbOrgLevel')
    is_active = models.IntegerField()

    class Meta:
        db_table = 'tb_org'

class TbUserOrg(models.Model):
    user = models.ForeignKey(TbUser)
    org = models.ForeignKey(TbOrg)
    create_date = models.DateTimeField()
    # org_role = models.ForeignKey(TbOrgRole)

    class Meta:
        db_table = 'tb_user_org'


class TbSite(models.Model):
    site_code = models.CharField(unique=True, max_length=50)
    site_name = models.CharField(max_length=50)
    area_code = models.CharField(max_length=10, blank=True, null=True)
    create_date = models.DateTimeField()

    class Meta:
        db_table = 'tb_site'

class TbFormdraft(models.Model):
    table_name = models.CharField(max_length=255, blank=True, null=True)
    table_content = models.TextField()
    creator = models.CharField(max_length=20)
    create_time = models.DateTimeField()
    modify_time = models.DateTimeField()
    status = models.IntegerField()
    tmpl = models.ForeignKey('TbForms')
    layout = models.CharField(max_length=30, blank=True, null=True)
    file1 = models.CharField(max_length=255, blank=True, null=True)
    file2 = models.CharField(max_length=255, blank=True, null=True)
    file3 = models.CharField(max_length=255, blank=True, null=True)
    file4 = models.CharField(max_length=255, blank=True, null=True)
    file5 = models.CharField(max_length=255, blank=True, null=True)
    file6 = models.CharField(max_length=255, blank=True, null=True)
    alias = models.CharField(max_length=255, blank=True, null=True)
    wfs = models.TextField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'tb_formdraft'
